using IGeekFan.AspNetCore.Knife4jUI;
using Medical.Api.Read.AutoMapper;
using Medical.Api.Read.Service.BasicManagement;
using Medical.Api.Read.Service.RBAC;
using Medical.Api.Read.Service.WmsService;
using Medical.Interstructrue;
using Medical.Interstructrue.Base;
using Microsoft.EntityFrameworkCore;
using NLog.Web;
using System.Reflection;
using Yitter.IdGenerator;var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(x =>
{
    var path = Path.Combine(AppContext.BaseDirectory, "Medical.Api.Read.xml");
    x.IncludeXmlComments(path,true);
});
// ���ݿ�����
builder.Services.AddDbContext<MedicalDbContext>(x =>
{
    x.UseMySql(builder.Configuration.GetConnectionString("MySQL"), new MySqlServerVersion("5.7"));
});
//MediatR
builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));
// ��־
builder.Host.UseNLog();
// ѩ���㷨
YitIdHelper.SetIdGenerator(new IdGeneratorOptions());
// �Զ�ӳ��
builder.Services.AddAutoMapper(x =>
{
    x.AddProfile<BasicManagementMapper>();
    x.AddProfile<DepartmentManagementMapper>();
    x.AddProfile<InventoryManagementMapper>();
    x.AddProfile<PackagingSterilizationMapper>();
    x.AddProfile<RecyclingCleaningMapper>();
    x.AddProfile<RBACMapper>();
    x.AddProfile<WmsMapper>();
});
// �ִ�
builder.Services.AddScoped(typeof(IBaseRepository<>), typeof(BaseRepository<>));
//����
builder.Services.AddScoped(typeof(IRBACService), typeof(RBACService));
builder.Services.AddScoped(typeof(IWmsService), typeof(WmsService));
builder.Services.AddScoped(typeof(IBasicManagementService), typeof(BasicManagementService));
var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseKnife4UI();
    app.UseSwaggerUI();
}
// CORS
app.UseCors(x => x.AllowAnyHeader().AllowAnyOrigin().AllowAnyMethod());
// ��̬�ļ�
app.UseStaticFiles();
app.UseAuthorization();

app.MapControllers();

app.Run();
